package kau.controller;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import kau.dao.AttendInfoDAOImpl;
import kau.dao.CourseDAOImpl;
import kau.dao.CustomerDAOImpl;
import kau.vo.*;

import org.apache.catalina.Session;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import common.DateUtil;
import common.Util;

public class AttendInfoAction extends MultiActionController {
	

	
	public ModelAndView AttendInfoAnalysis(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView nextPage = new ModelAndView();
		String selectedMonth = request.getParameter("selectedMonth");
		HttpSession session = request.getSession();
		
		int courseId = Integer.parseInt(session.getAttribute("courseId").toString());
		List custIdList=null;
		String startDate = CourseDAOImpl.getInstance().getCourse(courseId).getStartDate();
		String endDate = CourseDAOImpl.getInstance().getCourse(courseId).getEndDate();
		System.out.println("courseId"+courseId);
		Course course = CourseDAOImpl.getInstance().getCourse(courseId);
		float absenceGrade = (float) course.getAbsenceGrade();
		float earlyGrade = (float)course.getEarlyGrade();
		float lateGrade = (float)course.getLateGrade();
		
		int courseEndTime = Integer.parseInt(DateUtil.getTimeNotsemi(course.getEndTime()));
		Date now = new Date();
		int currentTime = now.getHours()*100+now.getMinutes();	// 현재시간
		//System.out.println("absenceGrade"+course.getAbsenceGrade());
		//System.out.println("earlyGrade"+earlyGrade);
		//System.out.println("lateGrade"+lateGrade);
		
		
		int allAttendCnt, pastAttendCnt,leftAttendCnt;
		float progress;
		
		ArrayList<AttendInfo> allAttendInfoList = null;
		if(selectedMonth.equals("all")){
			allAttendInfoList = // 모든기간의 출석정보리스트 
					AttendInfoDAOImpl.getInstance().getAllPeriodAttendInfoList(courseId);
			custIdList = AttendInfoDAOImpl.getInstance().getAllCustId(courseId);
			allAttendCnt = DateUtil.getNotHolidayDayCount(startDate,endDate);
			pastAttendCnt = DateUtil.getNotHolidayDayCount(startDate,DateUtil.getToday());
			
			if(courseEndTime>currentTime && pastAttendCnt!=0){
				pastAttendCnt =pastAttendCnt-1; 
			}
			leftAttendCnt = allAttendCnt-pastAttendCnt;
			progress = (float)pastAttendCnt/(float)allAttendCnt*100;
			
		}
		else{
			request.setAttribute("selectedMonth",request.getParameter("selectedMonth"));
			allAttendInfoList = // 특정달의 출석정보리스트 
					AttendInfoDAOImpl.getInstance().getMonthAttendInfoList(courseId, selectedMonth);
			custIdList = AttendInfoDAOImpl.getInstance().getMonthCustId(courseId,selectedMonth);
			
			
			
			/*해당월의 마지막 날짜 가져오기			*/
			String[] temp = selectedMonth.split("-");
			int year = Integer.parseInt(temp[0]);
			int month = Integer.parseInt(temp[1]);
			GregorianCalendar cld = new GregorianCalendar (year, month - 1, 1 );
			
			String startDate_ = selectedMonth+"-01";	
			String endDate_ = selectedMonth+"-"+cld.getActualMaximum ( Calendar.DAY_OF_MONTH );
			
			System.out.println(year+"년"+month+"월의 마지막날은"+cld.getActualMaximum ( Calendar.DAY_OF_MONTH ));
			allAttendCnt = DateUtil.getNotHolidayDayCount(startDate_,endDate_);
			
			pastAttendCnt = DateUtil.getNotHolidayDayCount(startDate_,DateUtil.getToday());
			if(courseEndTime>currentTime && pastAttendCnt!=0){
				pastAttendCnt =pastAttendCnt-1; 
			}
			if(pastAttendCnt>=cld.getActualMaximum ( Calendar.DAY_OF_MONTH ))
				pastAttendCnt = allAttendCnt;
			leftAttendCnt = allAttendCnt-pastAttendCnt;
			progress = (float)pastAttendCnt/(float)allAttendCnt*100;
			progress = Float.parseFloat(String.format("%.2f",progress));
		}
		
		
		ArrayList<AttendInfo>[] personalAttendInfoList = new ArrayList[custIdList.size()];
		
		
		for(int i=0;i<custIdList.size();i++){
			personalAttendInfoList[i] = new ArrayList<AttendInfo>();
			for(int j=0;j<allAttendInfoList.size();j++){
				if(custIdList.get(i).toString().equals(allAttendInfoList.get(j).getCustId().toString())){
					personalAttendInfoList[i].add(allAttendInfoList.get(j));
				}
			}
		}
		
		// personalAttendInfoList -> 개인attendInfo정보리스트
		System.out.println("custIdList.size()"+custIdList.size());
		ArrayList<AttendInfoAnalysis> attendInfoAnalysisList = new ArrayList<>();
		for(int i=0;i<custIdList.size();i++){
			int absenceCnt=0;
			int earlyLeavingCnt=0;
			int lateCnt=0;
			int earlylateCnt =0;
			int nomalCnt=0; 
			for(int j=0; j<personalAttendInfoList[i].size();j++){
				
				if(personalAttendInfoList[i].get(j).getCheckInState()==1 && personalAttendInfoList[i].get(j).getCheckOutState()==1){
					absenceCnt++;
					
				}else if(personalAttendInfoList[i].get(j).getCheckInState()==2 && personalAttendInfoList[i].get(j).getCheckOutState()==2){
					nomalCnt++;
				}
				else if(personalAttendInfoList[i].get(j).getCheckInState()==3&&personalAttendInfoList[i].get(j).getCheckOutState()==3){
					earlylateCnt++;
					
				}
				else if(personalAttendInfoList[i].get(j).getCheckInState()==3 && personalAttendInfoList[i].get(j).getCheckOutState()==2){
					lateCnt++;
					
				}else if(personalAttendInfoList[i].get(j).getCheckInState()==2 &&personalAttendInfoList[i].get(j).getCheckOutState()==3){
					earlyLeavingCnt++;
				}
			
				
			
			}
			if(courseEndTime>currentTime && absenceCnt!=0){
				absenceCnt--;
			}
			
			String custId = personalAttendInfoList[i].get(0).getCustId();
			String custName = personalAttendInfoList[i].get(0).getCustName();
			
			
		
			float attendGrade = -(absenceCnt*absenceGrade) -(earlyGrade*earlyLeavingCnt)-(lateCnt*lateGrade);
			float totalGrade = 100+attendGrade;
			
			attendGrade = Float.parseFloat(String.format("%.2f",attendGrade));
			totalGrade = Float.parseFloat(String.format("%.2f",totalGrade));
			AttendInfoAnalysis attendInfoAnalysis = new AttendInfoAnalysis(custId, custName, absenceCnt, earlyLeavingCnt, lateCnt, earlylateCnt, nomalCnt, attendGrade, totalGrade, allAttendCnt, pastAttendCnt, leftAttendCnt, progress);
			
			attendInfoAnalysisList.add(attendInfoAnalysis);
		}
		
		request.setAttribute("attendInfoAnalysisList", attendInfoAnalysisList);
		request.setAttribute("monthList", AttendInfoDAOImpl.getInstance().getMonthList(courseId, startDate, endDate));
		nextPage.setViewName("/course/index.jsp?content=/attendInfo/attendInfoAnalysis.jsp");
		return nextPage;
	}
	
	public ModelAndView periodicalAttendInfoExcelDown(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView nextPage = new ModelAndView();
		
		System.out.println("-------------");
		String startDate=request.getParameter("startDate");
		String endDate = request.getParameter("endDate");
		int courseId = Integer.parseInt(request.getParameter("courseId"));
		String courseName = CourseDAOImpl.getInstance().getCourse(courseId).getCourseName();
		int courseEndTime = Integer.parseInt(DateUtil.getTimeNotsemi(CourseDAOImpl.getInstance().getCourse(courseId).getEndTime()));
		
		Date now = new Date();
		int currentTime = now.getHours()*100+now.getMinutes();	// 현재시간
		String today = DateUtil.getToday();
		System.out.println("today:"+today);
		
		ArrayList<AttendInfo> attendInfoList = AttendInfoDAOImpl.getInstance().getPeriodicalAttendInfoList(courseId,startDate,endDate);
		List dayList = AttendInfoDAOImpl.getInstance().getPeriodicalDay(courseId, startDate, endDate);
		for(int i =0; i<attendInfoList.size();i++){
			int checkInState = attendInfoList.get(i).getCheckInState();
			int checkOutState = attendInfoList.get(i).getCheckOutState();
			String checkInTime= attendInfoList.get(i).getCheckInTime();
			String checkOutTime= attendInfoList.get(i).getCheckOutTime();
			String custId = attendInfoList.get(i).getCustId();
			String custName = CustomerDAOImpl.getInstance().getCustomer(custId).getCustName();
			attendInfoList.get(i).setCourseName(courseName);
			attendInfoList.get(i).setCustName(custName);
			
			if(checkInState==2 && checkOutState==2){
				attendInfoList.get(i).setState("정상");
				System.out.println("정상입니다.");
			}
			else if(checkInState==2 && checkOutState ==3)
			{
				attendInfoList.get(i).setState("조퇴");
				System.out.println("조퇴입니다.");
			}
			else if(checkInState==3 && checkOutState ==2)
			{
				attendInfoList.get(i).setState("지각");
				System.out.println("지각입니다.");
			}
			else if(checkInState==3 && checkOutState ==3)
			{
				attendInfoList.get(i).setState("지각+조퇴");
				System.out.println("지각+조퇴입니다.");
			}
			else if(checkInState==1 && checkOutState ==1)
			{
				if(DateUtil.getToday().equals(attendInfoList.get(i).getDay())&& courseEndTime>currentTime){
					System.out.println("attendInfoList.get(i).getDay():"+attendInfoList.get(i).getDay());
					System.out.println("DateUtil.getToday()"+DateUtil.getToday());
				}
				else{
					attendInfoList.get(i).setState("결석");
					System.out.println("결석입니다.");
				}
			}
		}
		request.setAttribute("dayList",dayList);
		request.setAttribute("periodical","ok");
		request.setAttribute("startDate",startDate);
		request.setAttribute("endDate",endDate);
		request.setAttribute("attendInfoList", attendInfoList);
		System.out.println(attendInfoList);
		nextPage.setViewName("/attendInfo/excelDown.jsp");
		return nextPage;
	}
	public ModelAndView personalAttendInfoExcelDown(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView nextPage = new ModelAndView();
		String custId = new String(request.getParameter("custId").getBytes("8859_1"),"utf-8");
		String custName = CustomerDAOImpl.getInstance().getCustomer(custId).getCustName();
		System.out.println(custId);
		int courseId = Integer.parseInt(request.getParameter("courseId"));
		String courseName = CourseDAOImpl.getInstance().getCourse(courseId).getCourseName();
		ArrayList<AttendInfo> attendInfoList = AttendInfoDAOImpl.getInstance().getAttendInfoList(custId, courseId);
		int courseEndTime = Integer.parseInt(DateUtil.getTimeNotsemi(CourseDAOImpl.getInstance().getCourse(courseId).getEndTime()));
		Date now = new Date();
		int currentTime = now.getHours()*100+now.getMinutes();	// 현재시간
		System.out.println("courseEndtime: "+courseEndTime +"currentTime"+currentTime);
		for(int i =0; i<attendInfoList.size();i++){
			int checkInState = attendInfoList.get(i).getCheckInState();
			int checkOutState = attendInfoList.get(i).getCheckOutState();
			String checkInTime= attendInfoList.get(i).getCheckInTime();
			String checkOutTime= attendInfoList.get(i).getCheckOutTime();
			attendInfoList.get(i).setCustName(custName);
			attendInfoList.get(i).setCourseName(courseName);
			if(checkInState==2 && checkOutState==2){
				attendInfoList.get(i).setState("정상");
				System.out.println("정상입니다.");
			}
			else if(checkInState==2 && checkOutState ==3)
			{
				attendInfoList.get(i).setState("조퇴");
				System.out.println("조퇴입니다.");
			}
			else if(checkInState==3 && checkOutState ==2)
			{
				attendInfoList.get(i).setState("지각");
				System.out.println("지각입니다.");
			}
			else if(checkInState==3 && checkOutState ==3)
			{
				attendInfoList.get(i).setState("지각+조퇴");
				System.out.println("지각+조퇴입니다.");
			}
			else if(checkInState==1 && checkOutState ==1)
			{
				
				if(DateUtil.getToday().equals(attendInfoList.get(i).getDay())&& courseEndTime>currentTime){
				
				}
				else{
					attendInfoList.get(i).setState("결석");
					System.out.println("결석입니다.");
				}
			}
		}
		request.setAttribute("attendInfoList", attendInfoList);
		System.out.println(attendInfoList);
		nextPage.setViewName("/attendInfo/excelDown.jsp");
		return nextPage;
	}
	
	public ModelAndView levelCheckAndGetAttendInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView nextPage = new ModelAndView();
		String custId = request.getParameter("custId");
		String custName = CustomerDAOImpl.getInstance().getCustomer(custId).getCustName();
		int courseId = Integer.parseInt(request.getParameter("courseId"));
		int custLevel = CustomerDAOImpl.getInstance().getCustomer(custId).getCustLevel();
		
		int courseStartTime = Integer.parseInt(DateUtil.getTimeNotsemi(CourseDAOImpl.getInstance().getCourse(courseId).getStartTime()));
		int courseEndTime = Integer.parseInt(DateUtil.getTimeNotsemi(CourseDAOImpl.getInstance().getCourse(courseId).getEndTime()));
		
		System.out.println("courseStartTime : "+courseStartTime);
		System.out.println("courseEndTime : "+courseEndTime);
		Date now = new Date();
		int currentTime = now.getHours()*100+now.getMinutes();	// 현재시간
		
		if(custLevel ==3){	// 학생의 출석정보조회
			
			System.out.println("학생입니다");
			// 현재달의 개인 출결정보리스트 가져오기(체크인상태, 체크아웃상태, 체크인시간,체크아웃시간, 날짜)
			ArrayList<AttendInfo> attendInfoList = AttendInfoDAOImpl.getInstance().getAttendInfoList(custId, courseId);
			
			
			System.out.println(attendInfoList);
			//id,title,start,url
			JSONArray jsonArr = new JSONArray();
			
			
			for(int i=0; i<attendInfoList.size();i++){
				int checkInState = attendInfoList.get(i).getCheckInState();
				int checkOutState = attendInfoList.get(i).getCheckOutState();
				String checkInTime= attendInfoList.get(i).getCheckInTime();
				String checkOutTime= attendInfoList.get(i).getCheckOutTime();
				JSONObject jsonObj = new JSONObject();
				jsonObj.put("id", i);
				jsonObj.put("start",attendInfoList.get(i).getDay());
				
				if(checkInState==2 && checkOutState==2){
					jsonObj.put("title", "정상\n"+checkInTime+" - "+checkOutTime);
					System.out.println("정상입니다.");
					jsonArr.add(jsonObj);
				}
				else if(checkInState==2 && checkOutState ==3)
				{
					jsonObj.put("title", "조퇴\n"+checkInTime+" - "+checkOutTime);
					System.out.println("조퇴입니다.");
					jsonArr.add(jsonObj);
				}else if(checkInState==3 && checkOutState ==3)
				{
					jsonObj.put("title", "지각+조퇴\n"+checkInTime+" - "+checkOutTime);
					System.out.println("지각+조퇴입니다.");
					jsonArr.add(jsonObj);
				}
				else if(checkInState==3)
				{
					jsonObj.put("title", "지각\n"+checkInTime+" - "+checkOutTime);
					System.out.println("지각입니다.");
					jsonArr.add(jsonObj);
				}
				
				else if(checkInState==1 && checkOutState ==1)
				{
					if(DateUtil.getToday().equals(attendInfoList.get(i).getDay())&& courseEndTime>currentTime){
						continue;
					}
					else{
					
					jsonObj.put("title", "결석");
					System.out.println("결석입니다.");
					jsonArr.add(jsonObj);
					}
				}
				
			}
			
			
			System.out.println("------------\n"+jsonArr.toString());
			request.setAttribute("json", jsonArr);
			nextPage.setViewName("/course/index.jsp?content=/attendInfo/personalAttendInfo.jsp?json="+jsonArr+"&custName="+custName+"&custId="+custId);
			//nextPage.setViewName("/attendInfo/personalAttendInfo.jsp?json="+jsonArr);
		}
		
		else // 강사의 출석정보조회
		{
			String day=null;
			if(request.getParameter("day") == null)
				day = getNowDate();
			else
				day = request.getParameter("day");
			System.out.println(day);
			ArrayList<AttendInfo> attendInfoList 
			=AttendInfoDAOImpl.getInstance().getAllAttendInfoList(courseId, day);
			System.out.println("attendInfoList : "+attendInfoList);
			
			for(int i =0; i<attendInfoList.size();i++){
				int checkInState = attendInfoList.get(i).getCheckInState();
				int checkOutState = attendInfoList.get(i).getCheckOutState();
				String checkInTime= attendInfoList.get(i).getCheckInTime();
				String checkOutTime= attendInfoList.get(i).getCheckOutTime();
				
				if(checkInState==2 && checkOutState==2){
					
					attendInfoList.get(i).setState("정상");
					System.out.println("정상입니다.");
				}
				else if(checkInState==2 && checkOutState ==3)
				{
					attendInfoList.get(i).setState("조퇴");
					System.out.println("조퇴입니다.");
				}else if(checkInState==3 && checkOutState ==3)
				{
					attendInfoList.get(i).setState("지각+조퇴");
					System.out.println("지각+조퇴입니다.");
				}
				else if(checkInState==3)
				{
					attendInfoList.get(i).setState("지각");
					System.out.println("지각입니다.");
				}
				
				else if(checkInState==1 && checkOutState ==1)
				{
					if(DateUtil.getToday().equals(day)&& courseEndTime>currentTime){
						
					}
					else{
						attendInfoList.get(i).setState("결석");
						System.out.println("결석입니다.");
					}
				}
				
			}
			request.setAttribute("attendInfoList", attendInfoList);
			request.setAttribute("day", day);
			nextPage.setViewName("/course/index.jsp?content=/attendInfo/courseAttendInfo.jsp");
		}
		
		return nextPage;
	}
	
	public static String getNowDate(){
		Calendar calendar = new GregorianCalendar(Locale.KOREA);
		java.util.Date trialTime = new java.util.Date();
		calendar.setTime(trialTime);
		
		String year = String.valueOf(calendar.get(Calendar.YEAR));
		String month = null;
		if(calendar.get(Calendar.MONTH)+1 < 10)
			month = "0"+String.valueOf(calendar.get(Calendar.MONTH)+1);
		else
			month = String.valueOf(calendar.get(Calendar.MONTH)+1);
		
			
		String date = null;
		if(calendar.get(Calendar.DATE) <10)
			date= "0"+String.valueOf(calendar.get(Calendar.DATE));
		else
			date = String.valueOf(calendar.get(Calendar.DATE));
		
		return year+"-"+month+"-"+date;
	}
	
	
	// getAttendInfo 해서 개인의 정보를 가져온뒤 넥스트페이지에 수정 페이지
	public ModelAndView getAttendInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView nextPage = new ModelAndView();
		
		
		String custId = request.getParameter("custId");
		String custName = new String(request.getParameter("custName").getBytes("8859_1"),"utf-8");
		String state = new String(request.getParameter("state").getBytes("8859_1"),"utf-8");
		String checkInTime=request.getParameter("checkInTime");
		String checkOutTime=request.getParameter("checkOutTime");
		String day = request.getParameter("day");
		System.out.println(custName+state);
		request.setAttribute("custId", custId);
		request.setAttribute("custName", custName);
		request.setAttribute("state", state);
		request.setAttribute("checkInTime", checkInTime);
		request.setAttribute("checkOutTime", checkOutTime);
		request.setAttribute("day", day);
		
		nextPage.setViewName("/course/index.jsp?content=/attendInfo/update_attendInfo.jsp");
		
		return nextPage;
	}
	
	public ModelAndView update(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView nextPage = new ModelAndView();
		String custId = request.getParameter("custId");
		int courseId = Integer.parseInt(request.getParameter("courseId"));
		String day = request.getParameter("day");
		String checkInTime = request.getParameter("checkInTime");
		String checkOutTime = request.getParameter("checkOutTime");
		String changedState = request.getParameter("changedState");
		int checkInState=0, checkOutState=0;
		if(changedState.equals("정상")){
			checkInState =2;
			checkOutState=2;
		}
		else if(changedState.equals("조퇴")){
			checkInState =2;
			checkOutState=3;
		}
		else if(changedState.equals("지각+조퇴")){
			checkInState =3;
			checkOutState=3;
		}
		else if(changedState.equals("지각")){
			checkInState =3;
			checkOutState=2;
		}
		else if(changedState.equals("결석")){
			checkInState =1;
			checkOutState=1;
		}
		AttendInfo attendInfo = new AttendInfo(custId, courseId, day, checkInState, checkOutState, checkInTime, checkOutTime);
		System.out.println("attendInfo:"+attendInfo);
		AttendInfoDAOImpl.getInstance().update(attendInfo);
		
		String sessionCustId = request.getParameter("sessionCustId");
		
		//nextPage.setViewName("/course/index.jsp?content=/attendInfo/courseAttendInfo.jsp");
		nextPage.setViewName("levelCheckAndGetAttendInfo.attendInfo?custId="+sessionCustId+"&day="+day+"&courseId="+courseId);
		return nextPage;
		
	}
	
	
	
	public ModelAndView getAttendView(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ModelAndView nextPage = new ModelAndView();
		String custId = request.getParameter("custId");
		int courseId = Integer.parseInt(request.getParameter("courseId"));
		int custLevel = CustomerDAOImpl.getInstance().getCustomer(custId).getCustLevel();
		
		int courseStartTime = Integer.parseInt(DateUtil.getTimeNotsemi(CourseDAOImpl.getInstance().getCourse(courseId).getStartTime()));
		int courseEndTime = Integer.parseInt(DateUtil.getTimeNotsemi(CourseDAOImpl.getInstance().getCourse(courseId).getEndTime()));
		Date now = new Date();
		int currentTime = now.getHours()*100+now.getMinutes();	// 현재시간
		
		System.out.println("courseStartTime : "+courseStartTime);
		System.out.println("courseEndTime : "+courseEndTime);
		
		// 현재달의 개인 출결정보리스트 가져오기(체크인상태, 체크아웃상태, 체크인시간,체크아웃시간, 날짜)
		ArrayList<AttendInfo> attendInfoList = AttendInfoDAOImpl.getInstance().getAttendInfoList(custId, courseId);
		
		
		System.out.println(attendInfoList);
		//id,title,start,url
		JSONArray jsonArr = new JSONArray();
		
		
		for(int i=0; i<attendInfoList.size();i++){
			int checkInState = attendInfoList.get(i).getCheckInState();
			int checkOutState = attendInfoList.get(i).getCheckOutState();
			String checkInTime= attendInfoList.get(i).getCheckInTime();
			String checkOutTime= attendInfoList.get(i).getCheckOutTime();
			
			
			
					
					
			JSONObject jsonObj = new JSONObject();
			jsonObj.put("id", i);
			jsonObj.put("start",attendInfoList.get(i).getDay());
			
			if(checkInState==2 && checkOutState==2){
				jsonObj.put("title", "정상\n"+checkInTime+" - "+checkOutTime);
				System.out.println("정상입니다.");
				attendInfoList.get(i).setState("정상");
				
			}
			else if(checkInState==2 && checkOutState ==3)
			{
				jsonObj.put("title", "조퇴\n"+checkInTime+" - "+checkOutTime);
				System.out.println("조퇴입니다.");
				attendInfoList.get(i).setState("조퇴");
				
			}
			else if(checkInState==3 && checkOutState ==3)
			{
				jsonObj.put("title", "지각+조퇴\n"+checkInTime+" - "+checkOutTime);
				System.out.println("지각+조퇴입니다.");
				attendInfoList.get(i).setState("지각+조퇴");
				
			}
			else if(checkInState==3)
			{
				jsonObj.put("title", "지각\n"+checkInTime+" - "+checkOutTime);
				System.out.println("지각입니다.");
				attendInfoList.get(i).setState("지각");
				
			}
			
			else if(checkInState==1 && checkOutState ==1)
			{
				if(DateUtil.getToday().equals(attendInfoList.get(i).getDay())&& courseEndTime>currentTime){
					continue;
				}
				else{
				
				jsonObj.put("title", "결석");
				System.out.println("결석입니다.");
				attendInfoList.get(i).setState("결석");
				}
			}
			
			else
				continue;
			
			jsonObj.put("url", "getAttendInfo.attendInfo?custId="+custId
					+"&custName="+CustomerDAOImpl.getInstance().getCustomer(custId).getCustName()+"&day="+attendInfoList.get(i).getDay()+
					"&state="+attendInfoList.get(i).getState()+"&checkInTime="+attendInfoList.get(i).getCheckInTime()+
					"&checkOutTime="+attendInfoList.get(i).getCheckOutTime());
			jsonArr.add(jsonObj);
		}
		
		System.out.println("------------\n"+jsonArr.toString());
		request.setAttribute("json", jsonArr);
		nextPage.setViewName("/course/index.jsp?content=/attendInfo/personalAttendInfo.jsp?json="+jsonArr);
		//nextPage.setViewName("/attendInfo/personalAttendInfo.jsp?json="+jsonArr);
		return nextPage;
	}
	

}
